import StaticStore from './StaticStore'
export default {
	/**
	 * @desc 菜单数据
	 */
	state: {
		url: StaticStore.state.baseUrl + '/m/index.php?c=home&a=topNav&json=1&id=3894',
		menus: [],
		currentMenu: {
			//			id: "37",
			//			parent_id: "0",
			//			name: "资讯",
			//			code: "zixun",
			//			logo: "",
			//			position: "homepagetop",
			//			status: "1",
			//			sorts: "100",
			//			is_blank: "0",
			//			url: "61",
			//			extra_info: "a:0:{}",
			//			temp: ""
		},
		links: [{
			name: '星河简介',
			path: '/introduce'
		}, {
			name: '广告服务',
			path: '/introduce'
		}, {
			name: '星河招聘',
			path: '/introduce'
		}, {
			name: '服务条款',
			path: '/introduce'
		}, {
			name: '网站律师',
			path: '/introduce'
		}, {
			name: '网站声明',
			path: '/introduce'
		}]
	},
	mutations: {
		updateMenus(state, data) {
			state.menus = data
			if(state.menuCode != "") {

				//				state.menuCode = ""
			}
		},
		changeMenu(state, menu) {
			state.currentMenu = menu
			//console.log("changeMenu: ", state.currentMenu.name)
		},
		selectMenu(state, code) {
			//console.log(state.menus)
			for(var i = 0; i < state.menus.length; i++) {
				if(state.menus[i].code == code) {
					state.currentMenu = state.menus[i]
				}
			}
		}
	},
	actions: {
		getMenuData({
			commit,
			state
		}) {
			$.ajax({
				url: state.url,
				dataType: 'jsonp',
				jsonp: 'callback',
				success: function(result) {
					commit('updateMenus', result)
					//console.log("get data success", result)
				},
				error: function(error) {
					console.log(error)
				}
			});
		}
	}
}